<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <style>
        .basic{
            width: 400px;
            height: 100px;
            border: 1px solid black;
            margin: 20px;
        }

        .happy{
            border: 4px solid red;
            background-color: rgba(255, 255, 0, 0.644);
            background: linear-gradient(30deg, yellow, pink, orange, yellow);
        }

        .normal{
            background-color: lightblue;
            border: 4px solid purple;
        }

        .sad{
            background-color: gray;
            border: 4px solid green;
        }

        .atguigu1{
            background-color: green;
        }

        .atguigu2{
            font-size: xx-large;
        }

        .atguigu3{
            border-radius: 20px;
        }


    </style>
</head>
<body>
    <div id="root">
        <!--固定不变的样式正常写，变化的样式通过v-bind绑定到class或style属性-->

        <!--绑定class样式-字符串写法：适用于样式的类名不确定，需要动态指定-->
        <div @click="changeMood" class="basic" v-bind:class="mood">
            {{name}}
        </div>

        <!--绑定多个class-数组写法，操作数组就是操作class，适用于绑定样式个数不定，名字也不定-->
        <div class="basic" :class="classArr">
            {{name}}
        </div>

        <!--绑定多个class-对象写法，适用于绑定样式个数确定，名字也确定，但是否用某个class不定-->
        <div class="basic" :class="classObj">
            {{name}}
        </div>

        <!--绑定style-对象写法，style中的属性必须是驼峰命名-->
        <div class="basic" :style="styleObj">
            {{name}}
        </div>

        <!--绑定style-数组对象写法，不常用-->
        <div class="basic" :style="[styleObj, styleObj2]">
            {{name}}
        </div>
    </div>
    <script>
        Vue.config.productionTip = false

        let vm = new Vue({
            el: "#root", 
            data: { 
                name: "atgg",
                mood: "normal",
                classArr: ['atguigu1', 'atguigu2', 'atguigu3'],
                classObj: {
                    atguigu1: true, //t表示使用样式atguigu1，f表示不用
                    atguigu2: false,
                    atguigu3: true,
                },
                styleObj: {
                    fontSize: '60px',
                    backgroundColor: 'gray'
                },
                styleObj2: {
                    border: '8px solid green',
                }
            },
            methods: {
                changeMood(){
                    //点击div随机切换class
                    let arr = ['happy', 'sad', 'normal']
                    let rand = Math.floor(3 * Math.random())
                    this.mood = arr[rand]
                }
            },
        })
    </script>
</body>
</html>